// 1.引入axios
import axios from "axios";
import NProgress  from "nprogress";
import 'nprogress/nprogress.css';

// 2.创建axios实例
const mockAjax = axios.create({
    baseURL:'/mock',
    timeout:3000
})

// 3.设置请求拦截器
mockAjax.interceptors.request.use(config=>{
    // 进度条开始
    NProgress.start();
    return config
})

// 4.设置响应拦截器
mockAjax.interceptors.response.use(res=>{
    NProgress.done();
    return res.data
},err=>{
    NProgress.done();
    return Promise.reject(new err(err.message))
})

export default mockAjax